#include<stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream>

// 队列的顺序存储

#define MAXSIZE 100
typedef int ElemType;
typedef struct {
    ElemType data[MAXSIZE];
    int front, rear;
} SqQueue;

void InitQueue(SqQueue &q){
    q.rear=q.front=0;
}

// 判断空队列
bool Empty(SqQueue q){
    if (q.rear==q.front) return true;
    else return false;
}

// 入队
bool EnQueue(SqQueue &q, ElemType e){
    if ((q.rear + 1)%MAXSIZE==q.front) return false;
    q.data[q.rear] = e;
    q.rear = (q.rear + 1)%MAXSIZE;
    return true; 
}

// 出队
bool DeQueue(SqQueue &q, ElemType &e){
    if (q.rear==q.front) return false;
    e = q.data[q.front];
    q.front = (q.front + 1)%MAXSIZE;
    return true; 
}

// 获取队头元素
bool GetHead(SqQueue q, ElemType &e){
    if (q.rear==q.front) return false;
    e = q.data[q.front];
    return true; 
}

int main(){
    SqQueue q;
    ElemType e;
    InitQueue(q);
    EnQueue(q, 1);
    EnQueue(q, 2);
    EnQueue(q, 3);
    EnQueue(q, 4);
    EnQueue(q, 5);
    DeQueue(q, e);
    printf("%d;;\n", e);
    DeQueue(q, e);
    printf("%d;;\n", e);
    DeQueue(q, e);
    printf("%d;;\n", e);
    GetHead(q, e);
    printf("%d;;\n", e);
    system("pause");
    return 0;
}